package 力扣日常刷题.木22一月.第08天0116;

import 力扣日常刷题.ListNode;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author 帅小伙
 * @date 2022/1/16
 * @description
 */
public class Demo01每日一题中等链表随机节点 {


    class Solution {
        ArrayList<Integer> list = new ArrayList<>();
        Random random;
        public Solution(ListNode head) {
            while (head != null) {
                list.add(head.val);
                head = head.next;
            }
            random = new Random();
        }

        public int getRandom() {
            return list.get(random.nextInt(list.size()));
        }
    }
}
